<?php
/*
YHM (Your Hosting Manager) - Copyright 2010 All Rights Reserved. - YHM Group
Released under the Simplified BSD Licence.

Website: http://yhm.co.uk
Licence: http://yhm.co.uk/about/#licence

file: admin/config.php
author: Charlie
*/

//Init Includes, Sessions and Page Info
require_once("../global.php");
session_start();
checklogin_admin();
$username = $_SESSION['user_name'];
$page = "config"
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>YHM - Admin CP - Configuration</title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../style.css" media="screen" />
</head>
<body>

<?php include("./header.php"); ?>

<h2>General Settings</h2>

<?php
if($_GET['action']=='do') {
	//title
	mysql_query("UPDATE ".TABLE_PREFIX."settings SET value='{$_POST['title']}' WHERE id='1'") or error("There was an error updating the settings! Please try again.");
	//url
	mysql_query("UPDATE ".TABLE_PREFIX."settings SET value='{$_POST['url']}' WHERE id='2'") or error("There was an error updating the settings! Please try again.");
	//sendmail
	mysql_query("UPDATE ".TABLE_PREFIX."settings SET value='{$_POST['sendmail']}' WHERE id='3'") or error("There was an error updating the settings! Please try again.");
	//index_redirect
	mysql_query("UPDATE ".TABLE_PREFIX."settings SET value='{$_POST['index_redirect']}' WHERE id='4'") or error("There was an error updating the settings! Please try again.");
	//signups
	mysql_query("UPDATE ".TABLE_PREFIX."settings SET value='{$_POST['signups']}' WHERE id='7'") or error("There was an error updating the settings! Please try again.");
	//tos
	mysql_query("UPDATE ".TABLE_PREFIX."settings SET value='{$_POST['tos']}' WHERE id='8'") or error("There was an error updating the settings! Please try again.");
	//free_activation
	mysql_query("UPDATE ".TABLE_PREFIX."settings SET value='{$_POST['free_activation']}' WHERE id='9'") or error("There was an error updating the settings! Please try again.");
	//p2h_activation
	mysql_query("UPDATE ".TABLE_PREFIX."settings SET value='{$_POST['p2h_activation']}' WHERE id='10'") or error("There was an error updating the settings! Please try again.");
	//p2h_field
	mysql_query("UPDATE ".TABLE_PREFIX."settings SET value='{$_POST['p2h_field']}' WHERE id='11'") or error("There was an error updating the settings! Please try again.");
}

echo "<form action='./config.php?action=do' method='post'>";

//title
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."settings WHERE id='1'");
$row = mysql_fetch_array($query);
echo "<h3>{$row['acpname']}</h3>";
echo "<p>{$row['desc']}</p>";
echo "<input type='text' value='{$row['value']}' name='{$row['name']}' />";

//url
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."settings WHERE id='2'");
$row = mysql_fetch_array($query);
echo "<h3>{$row['acpname']}</h3>";
echo "<p>{$row['desc']}</p>";
echo "<input type='text' value='{$row['value']}' name='{$row['name']}' />";

//sendmail
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."settings WHERE id='3'");
$row = mysql_fetch_array($query);
echo "<h3>{$row['acpname']}</h3>";
echo "<p>{$row['desc']}</p>";
echo "<input type='text' value='{$row['value']}' name='{$row['name']}' />";

//index_redirect
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."settings WHERE id='4'");
$row = mysql_fetch_array($query);

if($row['value']=="login")
{
	$lselected = "selected='selected'";
}
elseif($row['value']=="order")
{
	$oselected = "selected='selected'";
}

echo "<h3>{$row['acpname']}</h3>";
echo "<p>{$row['desc']}</p>";
echo "<select name='{$row['name']}'>
<option value='login' $lselected>Login Page</option>
<option value='order' $oselected>Order Form</option>
</select>";

//signups
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."settings WHERE id='7'");
$row = mysql_fetch_array($query);

if($row['value']=="1")
{
	$checked1 = "checked";
}
elseif($row['value']=="0")
{
	$checked0 = "checked";
}

echo "<h3>{$row['acpname']}</h3>";
echo "<p>{$row['desc']}</p>";
echo "<label for='signups1'><input type='radio' value='1' name='{$row['name']}' $checked1 id='signups1' />On</label>";
echo "<label for='signups2'><input type='radio' value='0' name='{$row['name']}' $checked0 id='signups2' />Off</label>";

//tos
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."settings WHERE id='8'");
$row = mysql_fetch_array($query);
echo "<h3>{$row['acpname']}</h3>";
echo "<p>{$row['desc']}</p>";
echo "<textarea name='{$row['name']}'>{$row['value']}</textarea>";

//free_activation
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."settings WHERE id='9'");
$row = mysql_fetch_array($query);

if ($row['value'] == "auto")
{
	$autoselected = "selected='selected'";
}
if ($row['value'] == "admin")
{
	$adminselected = "selected='selected'";
}
if ($row['value'] == "email")
{
	$emailselected = "selected='selected'";
}

echo "<h3>{$row['acpname']}</h3>";
echo "<p>{$row['desc']}</p>";
echo "<select name='{$row['name']}'>
<option value='auto' $autoselected>Instant Activation</option>
<option value='admin' $adminselected>Admin Validation</option>
<option value='email' $emailselected>Email Activation</option>
</select>";

//p2h_activation
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."settings WHERE id='10'");
$row = mysql_fetch_array($query);

if ($row['value'] == "auto")
{
	$autoselected = "selected='selected'";
}
if ($row['value'] == "admin")
{
	$adminselected = "selected='selected'";
}
if ($row['value'] == "email")
{
	$emailselected = "selected='selected'";
}

echo "<h3>{$row['acpname']}</h3>";
echo "<p>{$row['desc']}</p>";
echo "<select name='{$row['name']}'>
<option value='auto' $autoselected>Instant Activation</option>
<option value='admin' $adminselected>Admin Validation</option>
<option value='email' $emailselected>Email Activation</option>
</select>";

//p2h_field
$query = mysql_query("SELECT * FROM ".TABLE_PREFIX."settings WHERE id='11'");
$row = mysql_fetch_array($query);
echo "<h3>{$row['acpname']}</h3>";
echo "<p>{$row['desc']}</p>";
echo "<input type='text' value='{$row['value']}' name='{$row['name']}' />";
?>

<br /><br /><br />
<input type="submit" value="Update Settings" />
<br /><br />
</form>

<?php include ("../footer.php"); ?>
</div>
</body>
</html>